import { defineStore } from 'pinia'
import { GetMusic } from '../models/music'
import { GetAllDetailMusics, GetPlayLists } from '@/models/musciLists'
import { getMusic } from './getMusic'

const getMusic2 = getMusic()

export const musicStore = defineStore('musicStore', {
    state: () => {
        return {
            tryListenMusics: [] as GetAllDetailMusics[], //播放列表
            laterListenMusics: [] as GetAllDetailMusics[], //存放最近播放
        }
    },
    actions: {
        saveMus() {
            this.tryListenMusics = getMusic2.allMusics
        },
        pushLaterListenMusics(lists: GetAllDetailMusics) {
            var i = 0
            for (; i < this.laterListenMusics.length; i++) {
                if (this.laterListenMusics[i].id == lists.id) {
                    this.laterListenMusics.splice(i, 1)//先把符合条件的数据从当前数组中删除
                    break;
                }
            }
            this.laterListenMusics.unshift(lists)
        }
    },
    getters: {}
})

